/*
** get_args.c for  in /u/all/caille_c/cu/public/colle
** 
** Made by carole cailleux
** Login   <caille_c@epitech.net>
** 
** Started on  Mon Apr 26 20:39:13 2010 carole cailleux
** Last update Mon Apr 26 22:58:38 2010 carole cailleux
*/

#include <stdlib.h>
#include "starwars.h"

void		get_values(t_params *params, char **av, int ac)
{
  int		i;

  i = 1;
  while (i < ac)
    {
      if (my_strlen(av[i]) == 2)
        {
          if (av[i][0] == '-' && av[i][1] == 'a')
            params->autofire = 1;
          else if (av[i][0] == '-' && av[i][1] == 't' && i < ac - 1)
            {
              params->speed = my_get_nbr(av[i + 1]);
              i++;
            }
          else if (av[i][0] == '-' && av[i][1] == 'l' && i < ac - 1)
            {
              params->lives = my_get_nbr(av[i + 1]);
              i++;
            }
          else
            my_puterror("Incorrect arguments.\n");
        }
      i++;
    }
}

void		fill_params(int ac, char **av, t_params *params)
{
  params->lives = LIVES;
  params->speed = SPEED;
  params->autofire = 0;
  params->points = 0;
  params->x = 30;
  params->y = 26;
  if (ac < 7)
    get_values(params, av, ac);
  else
    my_puterror("Too much arguments.\n");
  if (params->speed > 1000)
    {
      my_puterror("time must be between 1 and 1000");
      exit(EXIT_FAILURE);
    }
}
